﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SCCM_Client_Injector_2014
{
    public partial class MultiClientForm : Form
    {
        public static bool boolAcceptEnter;
        public MultiClientForm()
        {
            InitializeComponent();
            this.textBoxEntry.KeyDown += new System.Windows.Forms.KeyEventHandler(this.OnKeyDownHandlerEntry);
        }

        private void MultiClientForm_Load(object sender, EventArgs e)
        {
            // Get clipboard contents if text data, select all, set focus on "OK" button and activate the one-key/click to accept the list
            textBoxEntry.Text = Clipboard.GetText(TextDataFormat.Text);
            textBoxEntry.SelectionStart = 0;
            textBoxEntry.SelectionLength = textBoxEntry.Text.Length;
            this.buttonOK.Focus();
            boolAcceptEnter = true;
        }

        private void OnKeyDownHandlerEntry(object sender, KeyEventArgs e)
        {

            if (e.KeyCode == Keys.Enter)
            {
                if (boolAcceptEnter == true)
                {
                    PostClientData();
                }
            }

        }

        private void textBoxEntry_TextChanged(object sender, EventArgs e)
        {
            // Once we've changed something in the text box, we don't want <ENTER> to trigger a post/close of the window
            boolAcceptEnter = false;
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            PostClientData();
        }

        private void buttonClearTextBoxEntry_Click(object sender, EventArgs e)
        {
            textBoxEntry.Text = "";
            this.textBoxEntry.Focus();
        }

        private void PostClientData()
        {
            Main.MultiClientList = "";
            Main.ClientListResults.Clear();
            Main.MultiClientList = this.textBoxEntry.Text;
            this.Close();
        }
    }
}
